/**
 * FileName: CrmExportController
 * Author:   秋水浮萍
 * Date:     2020/10/3 21:31
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.crm.crm.controller;

import com.crm.crm.service.CrmExportService;
import com.crm.entity.Partner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.List;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author 秋水浮萍
 * @create 2020/10/3
 * @since 1.0.0
 */
@RestController
@Api(value = "伙伴导出接口")
@RequestMapping("/crm/crmexport")
public class CrmExportController {

    @Autowired
    private CrmExportService crmExportService;


    //资产导出
    @ApiOperation(value = "资产导出")
    @PostMapping("exportAssetInf")
    public ResponseEntity<byte[]> exportAssetInf(String createId,
                                                 String company, Integer partnerType, String belong, @RequestParam(value = "cities[]", required = false, defaultValue = "") String[] cities,
                                                 String orgType, String orgRemark, String typeId) {


        List<Partner> list = crmExportService.exportAssetInf(createId, company, 1, belong, cities, orgType, orgRemark, typeId);


        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XSSFWorkbook hssfWorkbook = new XSSFWorkbook();

        XSSFSheet sheet1 = hssfWorkbook.createSheet("资产伙伴");
        String[] headerList1 = {"序号", "录入人", "伙伴姓名", "性别", "手机号", "其他联系方式",
                "微信号", "电子邮箱", "单位名称 ", "联系地址", "工作部门", "工作岗位",
                "伙伴来源", "伙伴对应项目", "伙伴对应债权", "机构类型", "其他信息",
                "覆盖地区", "备注"};
        XSSFRow row = sheet1.createRow(0);
        for (int i = 0; i < headerList1.length; i++) {
            row.createCell(i).setCellValue(headerList1[i]);
        }

        int i = 0;
        for (Partner stat : list) {
            int j = 0;
            XSSFRow row1 = sheet1.createRow(++i);
            row1.createCell(j++).setCellValue(i);
            row1.createCell(j++).setCellValue(stat.getTrueName());
            row1.createCell(j++).setCellValue(stat.getName());
            row1.createCell(j++).setCellValue(stat.getSex());
            row1.createCell(j++).setCellValue(stat.getTelephone());
            String s = "";
            if (stat.getTelephoneList() != null) {
                s = stat.getTelephoneList().toString();
            }
            row1.createCell(j++).setCellValue(s);
            row1.createCell(j++).setCellValue(stat.getWeixin());
            row1.createCell(j++).setCellValue(stat.getEmail());
            row1.createCell(j++).setCellValue(stat.getCompany());
            row1.createCell(j++).setCellValue(stat.getAddress());
            row1.createCell(j++).setCellValue(stat.getDepartment());
            row1.createCell(j++).setCellValue(stat.getPost());
            row1.createCell(j++).setCellValue(stat.getSource());
            row1.createCell(j++).setCellValue(stat.getItem());
            row1.createCell(j++).setCellValue(stat.getDebt());
            String d = "";
            if (stat.getOrgType() != null) {
                for (String r : stat.getOrgType()
                ) {
                    d = d + r + ",";
                }
            }

            row1.createCell(j++).setCellValue(d);
            String ass = "";
            if (stat.getAssetInfo() != null) {
                ass = stat.getAssetInfo().toString();
            }
            row1.createCell(j++).setCellValue(ass);
            row1.createCell(j++).setCellValue(ArraytoString(stat.getOverArea()));
            row1.createCell(j++).setCellValue(stat.getNote());
        }

        try {
            hssfWorkbook.write(os);
            hssfWorkbook.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        HttpHeaders headers = new HttpHeaders();
        // headers.add("Content-Type", "application/octet-stream;charset=utf-8");
        headers.add("Content-Type", "application/vnd.ms-excel;charset=UTF-8");
        headers.add("Connection", "close");
        headers.add("Accept-Ranges", "bytes");
        headers.add("Access-Control-Expose-Headers", "Content-Disposition");
        String myFileName = URLEncoder.encode("资产.xls", Charset.forName("utf-8"));
        headers.add("Content-Disposition", "attachment;filename=" + myFileName);
        //   + new String( "汇总.xlsx".getBytes(Charset.forName("UTF-8")), Charset.forName("ISO-8859-1")));
        return ResponseEntity
                .ok()
                .headers(headers)
                //.contentType(MediaType.APPLICATION_OCTET_STREAM)
                .body(os.toByteArray());

    }

    //资金
    @ApiOperation(value = "资金导出")
    @PostMapping("exportFundInfo")
    public ResponseEntity<byte[]> exportFundInfo(String createId,
                                                 String company, Integer partnerType, String orgType,
                                                 String orgRemark, String currency,
                                                 String incomeType,
                                                 String struct, Integer scaleMin, Integer scaleMax,
                                                 String deadline,
                                                 @RequestParam(value = "cities[]", required = false, defaultValue = "") String[] cities,
                                                 String typeId, String typeName, Integer incomeRate) {


        List<Partner> list = crmExportService.exportFundInfo(createId, company, 2, orgType, orgRemark, currency, incomeType, struct, scaleMin, scaleMax, deadline, cities, typeId, typeName, incomeRate);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XSSFWorkbook hssfWorkbook = new XSSFWorkbook();
        XSSFSheet sheet1 = hssfWorkbook.createSheet("资金伙伴");
        String[] headerList1 = {"序号", "录入人", "伙伴姓名", "性别", "手机号", "其他联系方式",
                "微信号", "电子邮箱", "单位名称 ", "联系地址", "工作部门", "工作岗位",
                "伙伴来源", "伙伴对应项目", "伙伴对应债权", "机构类型", "其他信息",
                "覆盖地区", "备注"};
        XSSFRow row = sheet1.createRow(0);
        for (int i = 0; i < headerList1.length; i++) {
            row.createCell(i).setCellValue(headerList1[i]);
        }

        int i = 0;
        for (Partner stat : list) {
            int j = 0;
            XSSFRow row1 = sheet1.createRow(++i);
            row1.createCell(j++).setCellValue(i);
            row1.createCell(j++).setCellValue(stat.getTrueName());
            row1.createCell(j++).setCellValue(stat.getName());
            row1.createCell(j++).setCellValue(stat.getSex());
            row1.createCell(j++).setCellValue(stat.getTelephone());
            String s = "";
            if (stat.getTelephoneList() != null) {
                s = stat.getTelephoneList().toString();
            }
            row1.createCell(j++).setCellValue(s);
            row1.createCell(j++).setCellValue(stat.getWeixin());
            row1.createCell(j++).setCellValue(stat.getEmail());
            row1.createCell(j++).setCellValue(stat.getCompany());
            row1.createCell(j++).setCellValue(stat.getAddress());
            row1.createCell(j++).setCellValue(stat.getDepartment());
            row1.createCell(j++).setCellValue(stat.getPost());
            row1.createCell(j++).setCellValue(stat.getSource());
            row1.createCell(j++).setCellValue(stat.getItem());
            row1.createCell(j++).setCellValue(stat.getDebt());
            String d = "";
            if (stat.getOrgType() != null) {
                for (String r : stat.getOrgType()
                ) {
                    d = d + r + ",";
                }
            }
            row1.createCell(j++).setCellValue(d);
            String ass = "";
            if (stat.getFundInfo() != null) {
                ass = stat.getFundInfo().toString();
            }
            row1.createCell(j++).setCellValue(ass);
            row1.createCell(j++).setCellValue(ArraytoString(stat.getOverArea()));
            row1.createCell(j++).setCellValue(stat.getNote());
        }

        try {
            hssfWorkbook.write(os);
            hssfWorkbook.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        HttpHeaders headers = new HttpHeaders();
        // headers.add("Content-Type", "application/octet-stream;charset=utf-8");
        headers.add("Content-Type", "application/vnd.ms-excel;charset=UTF-8");
        headers.add("Connection", "close");
        headers.add("Accept-Ranges", "bytes");
        headers.add("Access-Control-Expose-Headers", "Content-Disposition");
        String myFileName = URLEncoder.encode("资金.xls", Charset.forName("utf-8"));
        headers.add("Content-Disposition", "attachment;filename=" + myFileName);
        //   + new String( "汇总.xlsx".getBytes(Charset.forName("UTF-8")), Charset.forName("ISO-8859-1")));
        return ResponseEntity
                .ok()
                .headers(headers)
                //.contentType(MediaType.APPLICATION_OCTET_STREAM)
                .body(os.toByteArray());

    }

    //退出
    @ApiOperation(value = "退出导出")
    @PostMapping("exportExitInfo")
    public ResponseEntity<byte[]> exportExitInfo(String createId,
                                                 String company, Integer partnerType, String exitType, String orgRemark,
                                                 String usage,
                                                 String typeId, String typeName, @RequestParam(value = "cities[]", required = false, defaultValue = "") String[] cities,
                                                 Integer abilityMin, Integer abilityMax) {


        List<Partner> list = crmExportService.exportExitInfo(createId, company, 3, exitType, orgRemark, usage, typeId, typeName, cities, abilityMin, abilityMax);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XSSFWorkbook hssfWorkbook = new XSSFWorkbook();
        XSSFSheet sheet1 = hssfWorkbook.createSheet("退出伙伴");
        String[] headerList1 = {"序号", "录入人", "伙伴姓名", "性别", "手机号", "其他联系方式",
                "微信号", "电子邮箱", "单位名称 ", "联系地址", "工作部门", "工作岗位",
                "伙伴来源", "伙伴对应项目", "伙伴对应债权", "退出类型", "其他信息",
                "覆盖地区", "备注"};
        XSSFRow row = sheet1.createRow(0);
        for (int i = 0; i < headerList1.length; i++) {
            row.createCell(i).setCellValue(headerList1[i]);
        }

        int i = 0;
        for (Partner stat : list) {
            int j = 0;
            XSSFRow row1 = sheet1.createRow(++i);
            row1.createCell(j++).setCellValue(i);
            row1.createCell(j++).setCellValue(stat.getTrueName());
            row1.createCell(j++).setCellValue(stat.getName());
            row1.createCell(j++).setCellValue(stat.getSex());
            row1.createCell(j++).setCellValue(stat.getTelephone());
            String s = "";
            if (stat.getTelephoneList() != null) {
                s = stat.getTelephoneList().toString();
            }
            row1.createCell(j++).setCellValue(s);
            row1.createCell(j++).setCellValue(stat.getWeixin());
            row1.createCell(j++).setCellValue(stat.getEmail());
            row1.createCell(j++).setCellValue(stat.getCompany());
            row1.createCell(j++).setCellValue(stat.getAddress());
            row1.createCell(j++).setCellValue(stat.getDepartment());
            row1.createCell(j++).setCellValue(stat.getPost());
            row1.createCell(j++).setCellValue(stat.getSource());
            row1.createCell(j++).setCellValue(stat.getItem());
            row1.createCell(j++).setCellValue(stat.getDebt());

            row1.createCell(j++).setCellValue(stat.getExitType());
            String ass = "";
            if (stat.getExitInfo() != null) {
                ass = stat.getExitInfo().toString();
            }
            row1.createCell(j++).setCellValue(ass);
            row1.createCell(j++).setCellValue(ArraytoString(stat.getOverArea()));
            row1.createCell(j++).setCellValue(stat.getNote());
        }

        try {
            hssfWorkbook.write(os);
            hssfWorkbook.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        HttpHeaders headers = new HttpHeaders();
        // headers.add("Content-Type", "application/octet-stream;charset=utf-8");
        headers.add("Content-Type", "application/vnd.ms-excel;charset=UTF-8");
        headers.add("Connection", "close");
        headers.add("Accept-Ranges", "bytes");
        headers.add("Access-Control-Expose-Headers", "Content-Disposition");
        String myFileName = URLEncoder.encode("退出.xls", Charset.forName("utf-8"));
        headers.add("Content-Disposition", "attachment;filename=" + myFileName);
        //   + new String( "汇总.xlsx".getBytes(Charset.forName("UTF-8")), Charset.forName("ISO-8859-1")));
        return ResponseEntity
                .ok()
                .headers(headers)
                //.contentType(MediaType.APPLICATION_OCTET_STREAM)
                .body(os.toByteArray());

    }

    //司法
    @ApiOperation(value = "司法导出")
    @PostMapping("exportJusticeInfo")
    public ResponseEntity<byte[]> exportJusticeInfo(String createId,
                                                    Integer partnerType, String company,
                                                    String post, @RequestParam(value = "cities[]", defaultValue = "") String[] cities) {


        List<Partner> list = crmExportService.exportJusticeInfo(createId, 4, company, post, cities);

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XSSFWorkbook hssfWorkbook = new XSSFWorkbook();
        XSSFSheet sheet1 = hssfWorkbook.createSheet("司法伙伴");
        String[] headerList1 = {"序号", "录入人", "伙伴姓名", "性别", "手机号", "其他联系方式",
                "微信号", "电子邮箱", "单位名称 ", "联系地址", "工作部门", "工作岗位",
                "伙伴来源", "伙伴对应项目", "伙伴对应债权", "机构类型", "其他信息",
                "覆盖地区", "备注"};
        XSSFRow row = sheet1.createRow(0);
        for (int i = 0; i < headerList1.length; i++) {
            row.createCell(i).setCellValue(headerList1[i]);
        }

        int i = 0;
        for (Partner stat : list) {
            int j = 0;
            XSSFRow row1 = sheet1.createRow(++i);
            row1.createCell(j++).setCellValue(i);
            row1.createCell(j++).setCellValue(stat.getTrueName());
            row1.createCell(j++).setCellValue(stat.getName());
            row1.createCell(j++).setCellValue(stat.getSex());
            row1.createCell(j++).setCellValue(stat.getTelephone());
            String s = "";
            if (stat.getTelephoneList() != null) {
                s = stat.getTelephoneList().toString();
            }
            row1.createCell(j++).setCellValue(s);
            row1.createCell(j++).setCellValue(stat.getWeixin());
            row1.createCell(j++).setCellValue(stat.getEmail());
            row1.createCell(j++).setCellValue(stat.getCompany());
            row1.createCell(j++).setCellValue(stat.getAddress());
            row1.createCell(j++).setCellValue(stat.getDepartment());
            row1.createCell(j++).setCellValue(stat.getPost());
            row1.createCell(j++).setCellValue(stat.getSource());
            row1.createCell(j++).setCellValue(stat.getItem());
            row1.createCell(j++).setCellValue(stat.getDebt());
            String d = "";
            if (stat.getOrgType() != null) {
                for (String r : stat.getOrgType()
                ) {
                    d = d + r + ",";
                }
            }
            row1.createCell(j++).setCellValue(d);
            String ass = "";
            if (stat.getJusticeInfo() != null) {
                ass = stat.getJusticeInfo().toString();
            }
            row1.createCell(j++).setCellValue(ass);
            row1.createCell(j++).setCellValue(ArraytoString(stat.getOverArea()));
            row1.createCell(j++).setCellValue(stat.getNote());
        }

        try {
            hssfWorkbook.write(os);
            hssfWorkbook.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        HttpHeaders headers = new HttpHeaders();
        // headers.add("Content-Type", "application/octet-stream;charset=utf-8");
        headers.add("Content-Type", "application/vnd.ms-excel;charset=UTF-8");
        headers.add("Connection", "close");
        headers.add("Accept-Ranges", "bytes");
        headers.add("Access-Control-Expose-Headers", "Content-Disposition");
        String myFileName = URLEncoder.encode("司法.xls", Charset.forName("utf-8"));
        headers.add("Content-Disposition", "attachment;filename=" + myFileName);
        //   + new String( "汇总.xlsx".getBytes(Charset.forName("UTF-8")), Charset.forName("ISO-8859-1")));
        return ResponseEntity
                .ok()
                .headers(headers)
                //.contentType(MediaType.APPLICATION_OCTET_STREAM)
                .body(os.toByteArray());

    }

    //同业
    @ApiOperation(value = "同业导出")
    @PostMapping("exportPeerInfo")
    public ResponseEntity<byte[]> exportPeerInfo(String createId,
                                                 String company, Integer partnerType, String orgType,
                                                 String bizListId, String coopListId,
                                                 @RequestParam(value = "cities[]", required = false, defaultValue = "") String[] cities) {


        List<Partner> list = crmExportService.exportPeerInfo(createId, company, 5, orgType, bizListId, coopListId, cities);

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XSSFWorkbook hssfWorkbook = new XSSFWorkbook();
        XSSFSheet sheet1 = hssfWorkbook.createSheet("同业伙伴");
        String[] headerList1 = {"序号", "录入人", "伙伴姓名", "性别", "手机号", "其他联系方式",
                "微信号", "电子邮箱", "单位名称 ", "联系地址", "工作部门", "工作岗位",
                "伙伴来源", "伙伴对应项目", "伙伴对应债权", "机构类型", "其他信息",
                "覆盖地区", "备注"};
        XSSFRow row = sheet1.createRow(0);
        for (int i = 0; i < headerList1.length; i++) {
            row.createCell(i).setCellValue(headerList1[i]);
        }

        int i = 0;
        for (Partner stat : list) {
            int j = 0;
            XSSFRow row1 = sheet1.createRow(++i);
            row1.createCell(j++).setCellValue(i);
            row1.createCell(j++).setCellValue(stat.getTrueName());
            row1.createCell(j++).setCellValue(stat.getName());
            row1.createCell(j++).setCellValue(stat.getSex());
            row1.createCell(j++).setCellValue(stat.getTelephone());
            String s = "";
            if (stat.getTelephoneList() != null) {
                s = stat.getTelephoneList().toString();
            }
            row1.createCell(j++).setCellValue(s);
            row1.createCell(j++).setCellValue(stat.getWeixin());
            row1.createCell(j++).setCellValue(stat.getEmail());
            row1.createCell(j++).setCellValue(stat.getCompany());
            row1.createCell(j++).setCellValue(stat.getAddress());
            row1.createCell(j++).setCellValue(stat.getDepartment());
            row1.createCell(j++).setCellValue(stat.getPost());
            row1.createCell(j++).setCellValue(stat.getSource());
            row1.createCell(j++).setCellValue(stat.getItem());
            row1.createCell(j++).setCellValue(stat.getDebt());
            String d = "";
            if (stat.getOrgType() != null) {
                for (String r : stat.getOrgType()
                ) {
                    d = d + r + ",";
                }
            }
            row1.createCell(j++).setCellValue(d);
            String ass = "";
            if (stat.getPeerInfo() != null) {
                ass = stat.getPeerInfo().toString();
            }
            row1.createCell(j++).setCellValue(ass);
            row1.createCell(j++).setCellValue(ArraytoString(stat.getOverArea()));
            row1.createCell(j++).setCellValue(stat.getNote());
        }

        try {
            hssfWorkbook.write(os);
            hssfWorkbook.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        HttpHeaders headers = new HttpHeaders();
        // headers.add("Content-Type", "application/octet-stream;charset=utf-8");
        headers.add("Content-Type", "application/vnd.ms-excel;charset=UTF-8");
        headers.add("Connection", "close");
        headers.add("Accept-Ranges", "bytes");
        headers.add("Access-Control-Expose-Headers", "Content-Disposition");
        String myFileName = URLEncoder.encode("同业.xls", Charset.forName("utf-8"));
        headers.add("Content-Disposition", "attachment;filename=" + myFileName);
        //   + new String( "汇总.xlsx".getBytes(Charset.forName("UTF-8")), Charset.forName("ISO-8859-1")));
        return ResponseEntity
                .ok()
                .headers(headers)
                //.contentType(MediaType.APPLICATION_OCTET_STREAM)
                .body(os.toByteArray());

    }

    //政府
    @ApiOperation(value = "政府导出")
    @PostMapping("exportOrgInfo")
    public ResponseEntity<byte[]> exportOrgInfo(String createId,
                                                Integer partnerType, String company,
                                                String post, @RequestParam(value = "cities[]", required = false, defaultValue = "") String[] cities) {


        List<Partner> list = crmExportService.exportOrgInfo(createId, 6, company, post, cities);

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XSSFWorkbook hssfWorkbook = new XSSFWorkbook();
        XSSFSheet sheet1 = hssfWorkbook.createSheet("政府伙伴");
        String[] headerList1 = {"序号", "录入人", "伙伴姓名", "性别", "手机号", "其他联系方式",
                "微信号", "电子邮箱", "单位名称 ", "联系地址", "工作部门", "工作岗位",
                "伙伴来源", "伙伴对应项目", "伙伴对应债权", "伙伴备注", "其他信息",
                "覆盖地区", "备注"};
        XSSFRow row = sheet1.createRow(0);
        for (int i = 0; i < headerList1.length; i++) {
            row.createCell(i).setCellValue(headerList1[i]);
        }

        int i = 0;
        for (Partner stat : list) {
            int j = 0;
            XSSFRow row1 = sheet1.createRow(++i);
            row1.createCell(j++).setCellValue(i);
            row1.createCell(j++).setCellValue(stat.getTrueName());
            row1.createCell(j++).setCellValue(stat.getName());
            row1.createCell(j++).setCellValue(stat.getSex());
            row1.createCell(j++).setCellValue(stat.getTelephone());
            String s = "";
            if (stat.getTelephoneList() != null) {
                s = stat.getTelephoneList().toString();
            }
            row1.createCell(j++).setCellValue(s);
            row1.createCell(j++).setCellValue(stat.getWeixin());
            row1.createCell(j++).setCellValue(stat.getEmail());
            row1.createCell(j++).setCellValue(stat.getCompany());
            row1.createCell(j++).setCellValue(stat.getAddress());
            row1.createCell(j++).setCellValue(stat.getDepartment());
            row1.createCell(j++).setCellValue(stat.getPost());
            row1.createCell(j++).setCellValue(stat.getSource());
            row1.createCell(j++).setCellValue(stat.getItem());
            row1.createCell(j++).setCellValue(stat.getDebt());
            String d = "";
            row1.createCell(j++).setCellValue(d);
            String ass = "";
            if (stat.getOrgInfo() != null) {
                ass = stat.getOrgInfo().toString();
            }
            row1.createCell(j++).setCellValue(ass);
            row1.createCell(j++).setCellValue(ArraytoString(stat.getOverArea()));
            row1.createCell(j++).setCellValue(stat.getNote());
        }

        try {
            hssfWorkbook.write(os);
            hssfWorkbook.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        HttpHeaders headers = new HttpHeaders();
        // headers.add("Content-Type", "application/octet-stream;charset=utf-8");
        headers.add("Content-Type", "application/vnd.ms-excel;charset=UTF-8");
        headers.add("Connection", "close");
        headers.add("Accept-Ranges", "bytes");
        headers.add("Access-Control-Expose-Headers", "Content-Disposition");
        String myFileName = URLEncoder.encode("政府.xls", Charset.forName("utf-8"));
        headers.add("Content-Disposition", "attachment;filename=" + myFileName);
        //   + new String( "汇总.xlsx".getBytes(Charset.forName("UTF-8")), Charset.forName("ISO-8859-1")));
        return ResponseEntity
                .ok()
                .headers(headers)
                //.contentType(MediaType.APPLICATION_OCTET_STREAM)
                .body(os.toByteArray());

    }

    public static String ArraytoString(Object[][] arr) {

        if (arr == null)
            return "null";

        int iMax = arr.length - 1;
        if (iMax == -1)
            return "[]";

        StringBuilder b = new StringBuilder();
        b.append("[");
        for (int i = 0; i <= iMax; i++) {
            if (arr[i].length == 0) {
                b.append("[]");
                continue;
            }else if (arr[i] == null) {
                b.append("[null]");
                continue;
            }
            b.append("[");
            for (int j = 0; j < arr[i].length; j++) {
                b.append("" + arr[i][j]);
                if (j == arr[i].length - 1) {
                    b.append("]");
                    continue;
                }
                b.append(",");
            }
        }
        b.append("]");
        return b.toString();
    }

}